{% extends "admin/base_site.html" %}

<!-- LOADING -->
{% load i18n adminmedia fb_tags fb_pagination %}

<!-- STYLESHEETS -->
{% block stylesheets %}
    {{ block.super }}
    {# <link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/changelist.css" /> #}
    <link rel="stylesheet" type="text/css" href="{{ settings_var.URL_FILEBROWSER_MEDIA }}css/filebrowser.css" />
{% endblock %}

<!-- JAVASCRIPTS -->
{% block javascripts %}
    {{ block.super }}
    {% ifequal query.pop '1' %} <!-- FileBrowseField -->
    <script language="javascript" type="text/javascript" src="{{ settings_var.URL_FILEBROWSER_MEDIA }}js/FB_FileBrowseField.js"></script>
    {% endifequal %}
    {% ifequal query.pop '2' %} <!-- TinyMCE -->
    <script language="javascript" type="text/javascript" src="{{ settings_var.URL_TINYMCE }}tiny_mce_popup.js"></script>
    <script language="javascript" type="text/javascript" src="{{ settings_var.URL_FILEBROWSER_MEDIA }}js/FB_TinyMCE.js"></script>
    {% if query.mce_rdomain %}<script language="javascript">document.domain = "{{ query.mce_rdomain }}"</script>{% endif %}
    {% endifequal %}
    {% ifequal query.pop '3' %} <!-- CKeditor (former "FCKeditor") -->
    <script language="javascript" type="text/javascript" src="{{ settings_var.URL_FILEBROWSER_MEDIA }}js/FB_CKeditor.js"></script>
    {% endifequal %}
    {{ media }}
    
    <script type="text/javascript" src="{% admin_media_prefix %}js/grappelli.change_list.js"></script>
    <script type="text/javascript" charset="utf-8">
        (function($) {
            $(document).ready(function() {
                {% if is_popup %}
                    // UGLY HACK: REMOVE ACTIONS and LIST_EDITABLES FOR POPUPS
                    // shouldn't be there in the first place, see
                    // http://code.djangoproject.com/ticket/11700
                    $('div#actions').hide();
                    $('input.action-select').parent().hide();
                    $('input#action-toggle').parent().hide();
                    $('div.changelist-results input').attr('disabled', 'disabled');
                    $('div.changelist-results select').attr('disabled', 'disabled');
                    $('div.changelist-results textarea').attr('disabled', 'disabled').addClass("mceNoEditor");
                    $('div#submit').hide();
                    $('.related-lookup, .add-another').attr("onClick", "return false;");
                    $('.vDateField').datepicker("disable");
                {% endif %}
                $("a.pulldown-actions-handler").bind("click", function() {
                    if (!$(this).parent().hasClass("open")) {
                        $("tr").removeClass("selected");
                        $(".pulldown-actions-container").removeClass("open");
                        $(this).parent().addClass("open");
                        $(this).parent().parent().parent().addClass("selected");
                    } else {
                        $(this).parent().removeClass("open");
                        $(this).parent().parent().parent().removeClass("selected");
                    }
                });
                $("a.fb_showpreview").bind("click", function() {
                    $(this).next(".fb_preview_container").toggle();
                });
                $('body').change_list();
                $(document).keypress(function(evt) {
                    if (evt.keyCode == '27') {
                        $(".pulldown-actions-container:visible").removeClass("open");
                        $(".pulldown-actions-container").parent().parent().removeClass("selected");
                        $(".fb_preview_container:visible").hide();
                    }
                });
                $(document).mousedown(function(evt) {
                    if ($(".pulldown-actions-container").is(":visible")) {
                        var $target = $(evt.target);
                        if (!$(evt.target).hasClass("pulldown-actions-container") && $target.parents(".pulldown-actions-container").length == 0) {
                            $(".pulldown-actions-container").removeClass("open");
                            $(".pulldown-actions-container").parent().parent().removeClass("selected");
                        }
                    }
                    if ($(".fb_preview_container").is(":visible")) {
                        var $target = $(evt.target);
                        if (!$(evt.target).is("a.fb_showpreview") &&! $(evt.target).hasClass("fb_preview_container") && $target.parents(".fb_preview_container").length == 0) {
                            $(".fb_preview_container").hide();
                        }
                    }
                });
            });
        })(django.jQuery);
    </script>
{% endblock %}

<!-- COLTYPE/BODYCLASS-- >
{% block bodyclass %}change-list filebrowser{% if query.pop %} popup{% endif %}{% endblock %}
{% block content-class %}content-flexible{% endblock %}

<!-- BREADCRUMBS -->
{% block breadcrumbs %}{% include "filebrowser/include/breadcrumbs.html" %}{% endblock %}

{% block object-tools %}
<ul class="tools">
    <li><a href="{% url fb_mkdir %}{% query_string '' 'p' %}">{% trans "New Folder" %}</a></li>
    <li><a href="{% url fb_upload %}{% query_string '' 'p' %}" class="focus">{% trans "Upload" %}</a></li>
</ul>
{% endblock %}

<!-- CONTENT -->
{% block content %}
    <div class="module changelist-filters">
        <!-- PAGINATION -->
        {% pagination %}
        <!-- FILTERS -->
        {% include "filebrowser/include/filter.html" %}
        <!-- SEARCH -->
        <div id="search" class="module search span-6">
            <form id="changelist-search" action="." method="get">
                <input type="text" size="40" name="q" value="{{ query.q }}" id="searchbar" />
                {% if query.filter_type %}<input type="hidden" name="filter_type" value="{{ query.filter_type }}" />{% endif %}
                {% if query.filter_date %}<input type="hidden" name="filter_date" value="{{ query.filter_date }}" />{% endif %}
                {% if query.o %}<input type="hidden" name="o" value="{{ query.o }}" />{% endif %}
                {% if query.ot %}<input type="hidden" name="ot" value="{{ query.ot }}" />{% endif %}
                {% if query.pop %}<input type="hidden" name="pop" value="{{ query.pop }}" />{% endif %}
                {% if query.type %}<input type="hidden" name="type" value="{{ query.type }}" />{% endif %}
                {% if query.format %}<input type="hidden" name="format" value="{{ query.format }}" />{% endif %}
                {% if query.dir %}<input type="hidden" name="dir" value="{{ query.dir }}" />{% endif %}
                <button class="search" type="submit" value="">&nbsp;</button>
            </form>
        </div>
        <br clear="all" />
    </div>
    <div id="changelist" class="container-full">
        <!-- RESULTS -->
        {% if results_var.results_current %}
        <div class="module changelist-results">
            <table cellspacing="0">
                {% include "filebrowser/include/tableheader.html" %}
                <tbody>
                {% include "filebrowser/include/filelisting.html" %}
                </tbody>
            </table>
        </div>
        {% endif %}
        <!-- PAGINATION -->
        {% pagination %}
    </div>

{% endblock %}
